home *** CD-ROM | disk | FTP | other *** search
-
- #pragma once
-
- #ifndef __FSSPECIFICATION__
- #define __FSSPECIFICATION__
-
- #include <ConditionalMacros.h>
- #include "MoreStrings.h"
-
- #include <Files.h>
- #include <Processes.h>
- #include <Resources.h>
-
- class TDescriptor;
-
- enum
- {
- kDontCreateFile = false,
- kForceFileCreation = true,
- kDefaultPerm = 0x7F
- };
-
-
- typedef SInt16 OpenFileRefNum;
- typedef SInt32 OffsetInFile;
- typedef SInt16 OpenResFileRefNum;
-
- enum
- {
- kInvalidOpenRefNum = -1,
- kInvalidOpenResRefNum = -1
- };
-
-
-
- class TString;
-
- //========================================================================================
- // CLASS TFSSpecification
- //========================================================================================
-
- class TFSSpecification
- {
- //
- // Only TOpenFileRefNum can open a file
- //
- friend class TOpenFileRefNum;
- friend class TOpenResFileRefNum;
-
- public:
- TFSSpecification();
- TFSSpecification(const FSSpec&);
- TFSSpecification(const TFSSpecification&);
- TFSSpecification(const TDescriptor&, Boolean forceCreate = false, OSType creator = 0, OSType fileType = 0);
-
- TFSSpecification(const ProcessSerialNumber& psn);
-
-
- ~TFSSpecification();
-
- const TFSSpecification& operator=(const TFSSpecification& rhs);
- Boolean operator==(const TFSSpecification& rhs) const;
-
- OSStatus Validate();
-
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- //:: Common methods of TFSSpecification
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-
- OSStatus Delete();
- OSStatus Move(TFSSpecification& destinationOfMove);
- OSStatus Rename(const TString& newName);
- OSStatus ExchangeFiles(TFSSpecification& exchangeWith);
-
- OSStatus GetFinderInfo(FInfo& fndrInfo) const;
- OSStatus SetFinderInfo(const FInfo& fndrInfo) const;
-
- OSStatus CreateNewChildFile(const TString& newName, OSType creator, OSType fileType, TFSSpecification& newFile) const;
- OSStatus CreateNewChildFolder(const TString& newName, TFSSpecification& newFolder) const;
-
- OSStatus ContainerSpecification(TFSSpecification& container) const;
- OSStatus VolumeSpecification(TFSSpecification& volume) const;
-
- OSStatus Name(TString& fileName) const;
-
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- //:: Less-common methods of TFSSpecification (Avoid using these routines)
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-
- operator FSSpec() const;
-
- operator const FSSpec*() const { return &fFileSpec; }
- operator FSSpec*() { return &fFileSpec; }
-
- SInt16 VRefNum() const { return fFileSpec.vRefNum; }
- SInt32 ParentDirID() const { return fFileSpec.parID; }
- OSStatus AdoptSpec(SInt16 vRefNum, SInt32 dirID);
-
- OSStatus GetDirID(SInt32& dirID) const;
- OSStatus MakeFSSpec(SInt16 vRefNum, SInt32 dirID, ConstStr255Param name);
-
- OSStatus CreateFile(OSType creator, OSType fileType, ScriptCode scriptTag = 0);
-
-
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- //:: Protected / private methods of TFSSpecification
- //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-
- protected:
-
- OSStatus Open(OpenFileRefNum& refNum, SInt8 permission = kDefaultPerm) const;
- OSStatus OpenResFile(OpenResFileRefNum& refNum, SInt32 permission) const;
-
- private:
-
- FSSpec fFileSpec;
-
-
- };
-
- //========================================================================================
- // CLASS TOpenFileRefNum
- //========================================================================================
-
- class TOpenFileRefNum
- {
- public:
-
- TOpenFileRefNum() : fRefNum(kInvalidOpenRefNum), fIsOpen(false) {}
- TOpenFileRefNum(const OpenFileRefNum& refNum) : fRefNum(refNum), fIsOpen(true) {}
-
- OSStatus Open(const TFSSpecification& fileToOpen, SInt8 permission = kDefaultPerm);
- OSStatus Close();
- Boolean IsOpen() { return fIsOpen; }
-
- OSStatus Read(SInt32* count, void* buffPtr);
- OSStatus Write(SInt32* count, void *buffPtr);
-
- OSStatus GetEndOfFile(OffsetInFile* logEOF);
- OSStatus SetEndOfFile(OffsetInFile logEOF);
- OSStatus GetFilePosition(OffsetInFile* filePos);
- OSStatus SetFilePosition(OffsetInFile posOff);
-
-
- protected:
-
- OSStatus SetFilePosition(SInt16 posMode, SInt32 posOff);
-
- private:
- OpenFileRefNum fRefNum;
- OffsetInFile fCurrentPosition;
- Boolean fIsOpen;
- };
-
- //
- // Maybe later....
- //
- #if 0
-
- struct FInfo {
- OSType fdType; /*the type of the file*/
- OSType fdCreator; /*file's creator*/
- unsigned SInt16 fdFlags; /*flags ex. hasbundle,invisible,locked, etc.*/
- Point fdLocation; /*file's location in folder*/
- SInt16 fdFldr; /*folder containing file*/
- };
-
- class TFinderInfo
- {
- public:
- TFinderInfo();
- TFinderInfo(const FInfo& fndrInfo);
-
- OSType FileType() { return fFinderInfo.fdType; }
- OSType FileCreator() { return fFinderInfo.fdCreator; }
- Point FileLocation()
-
- private:
- FInfo fFinderInfo;
- };
-
- #endif // if 0
-
-
- #endif
-